<!DOCTYPE html>
<html>
<head>
    <title>店铺变更管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="storeName" placeholder="搜索店铺名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/html" id="currentTableAvatarTpl">
    {{# if(d.storeAvatar != ''){ }}
    <img src="{{d.storeAvatar}}" width="45" alt="">
    {{# } else { }}
    <img src="${request.contextPath}/statics/images/avatar.png" width="45" alt="">
    {{# } }}
    <span>{{d.storeName}}</span>
</script>

<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 2){ }}
    <span class="layui-badge layui-bg-grey">已驳回</span>
    {{# } else if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">已通过</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-black">待审核</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:store:save")>
    {{# if(d.status == 0){ }}
    <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="more">操作 <i class="layui-icon layui-icon-down"></i></a>
    {{# } }}
    </#if>
</script>

<script type="text/javascript">
    layui.use(['dropdown', 'form', 'table'], function () {
        var $ = layui.jquery,
            dropdown = layui.dropdown,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('app/store/changes'),
            toolbar: false,
            // defaultToolbar: ['filter'],
            cols: [[
                {type: "numbers", width: 60},
                {field: 'store', title: '店铺名称', minWidth: 150, templet: '#currentTableAvatarTpl'},
                {field: 'newValue', title: '新名称', minWidth: 150},
                {field: 'oldValue', title: '原名称', minWidth: 150},
                {field: 'status', title: '状态', width: 100, templet: '#currentTableStatusTpl'},
                {field: 'createTime', title: '修改时间', width: 180},
                {field: 'remark', title: '备注', minWidth: 150},
                {title: '操作', width: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [15, 30, 50],
            limit: 15,
            page: true
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var that = this;
            var data = obj.data;
            if(obj.event === 'more'){
                //更多下拉菜单
                dropdown.render({
                    elem: that
                    ,show: true //外部事件触发即显示
                    ,data: [{
                        title: '通过'
                        ,templet: '<span class="text-blue"><i class="layui-icon layui-icon-ok"></i>{{d.title}}</span>'
                        ,id: 'pass'
                    }, {
                        title: '驳回'
                        ,templet: '<span class="text-red"><i class="layui-icon layui-icon-close"></i>{{d.title}}</span>'
                        ,id: 'reject'
                    }]
                    ,click: function(res, othis){
                        //根据 id 做出不同操作
                        var title = res.id === 'pass' ? '确定通过吗？' : '确定驳回吗？';
                        var status = res.id === 'pass' ? 1 : 2;
                        openPrompt(title, '填写说明', function(value){
                            submitFormData('app/store/changes-update', {id: data.id, status: status, content: value}, function(){table.reload('currentTableId')});
                        });
                    }
                });
            }
        });

        // 监听搜索操作
        initSearchForm('searchForm', 'currentTableId');

    });
</script>

</body>
</html>